package 集合.Map.Map中的常用方法.Test02;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapTest02 {
    public static void main(String[] args) {
        Map<Integer,String> m = new HashMap<>();
        m.put(1,"李容是猪！！");
        m.put(2,"张三");
        m.put(3,"李四");
        m.put(4,"王五");
        //第一种
        Set<Integer> keys = m.keySet();
        for(Integer key : keys){
            System.out.println(m.get(key));
        }

        System.out.println("=====================================");

        Iterator it = keys.iterator();
        while(it.hasNext()){
            System.out.println(m.get(it.next()));
        }

        System.out.println("=====================================");
        //第二种
        Set<Map.Entry<Integer,String>> set = m.entrySet();
        Iterator<Map.Entry<Integer,String>> it2 = set.iterator();
        while(it2.hasNext()){
            System.out.println(it2.next());
        }
        //上下两个while一样
        while(it2.hasNext()){
            Map.Entry<Integer,String> node = it2.next();
            Integer key = node.getKey();
            String value = node.getValue();
            System.out.println(key + "=" + value);
        }

        System.out.println("=====================================");

        for(Map.Entry<Integer,String> node : set){
            System.out.println(node.getKey() + "--->" + node.getValue());
        }
    }
}


























